<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增用户端消息提醒')" />
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-userMessage-add">
            <input type="hidden" class="form-control" name="userId" id="userId">
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">消息内容：</label>
                <div class="col-sm-8">
                    <textarea type="hidden" class="form-control" name="messageContent" rows="3" required></textarea>
                    <!--<div class="summernote" id="messageContent"></div>-->
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">消息状态：</label>
                <div class="col-sm-8">
                    <select name="messageStatus" class="form-control m-b" th:with="type=${@dict.getType('message_type')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">消息类型：</label>
                <div class="col-sm-8">
                    <select id="messageType" name="messageType" onchange="stateValue()" class="form-control m-b" th:with="type=${@dict.getType('message_classify')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div id="userNicknameDiv" class="form-group">
                <label class="col-sm-3 control-label">选择用户：</label>
                <div class="col-sm-8">
                    <input id="userNickname" name="userNickname" class="form-control" type="text" placeholder="请选择用户" onclick="userSelect()">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: summernote-js" />
    <script th:inline="javascript">
        var prefix = ctx + "zsyh/userMessage"
        $("#form-userMessage-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-userMessage-add').serialize());
            }
        }

        $(function() {
            $('.summernote').summernote({
                lang: 'zh-CN',
                callbacks: {
                    onChange: function(contents, $edittable) {
                        $("input[name='" + this.id + "']").val(contents);
                    },
                    onImageUpload: function(files) {
                        var obj = this;
                    	var data = new FormData();
                    	data.append("file", files[0]);
                    	$.ajax({
                            type: "post",
                            url: ctx + "common/uploadOSS",
                    		data: data,
                    		cache: false,
                    		contentType: false,
                    		processData: false,
                    		dataType: 'json',
                    		success: function(result) {
                    		    if (result.code == web_status.SUCCESS) {
                    		        $('#' + obj.id).summernote('insertImage', result.url);
                    		    } else {
                    		        $.modal.alertError(result.msg);
                    		    }
                    		},
                    		error: function(error) {
                    		    $.modal.alertWarning("图片上传失败。");
                    		}
                    	});
                    }
                }
            });
        });

        $(function() {
            //获取被选中的option标签
            var vs = $('#messageType  option:selected').val();
            if(vs == "2"){
                $("#userNicknameDiv").show();
            }else {
                $("#userNicknameDiv").hide();
            }
        })

        function stateValue() {
            //获取被选中的option标签
            var vs = $('#messageType  option:selected').val();
            if(vs == "2"){
                $("#userNicknameDiv").show();
            }else {
                $("#userNicknameDiv").hide();
            }
        }

        function userSelect() {
            var url = ctx+"zsyh/platformUser/messageView/";
            layer.open({
                type: 2,
                area: ['600px', ($(window).height()-50) + 'px'],
                fix: false,
                //不固定
                maxmin: true,
                shade: 0.3,
                title: "选择用户",
                content:  url,
                closeBtn: 1,
                // 弹层外区域关闭
                shadeClose: true,
                end: function(){
                    //location.reload();
                },
                cancel: function(index) {
                    //location.reload();
                }
            });
        }
        
    </script>
</body>
</html>